
package interceptors;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;


public class LoginCheckInterceptor implements Interceptor {
    
    public LoginCheckInterceptor() {
    }
    
    public void destroy() {
        
    }
    
    public void init() {
        
    }
    
    public String intercept(ActionInvocation actionInvocation) throws Exception {
        
        HttpServletRequest request = ServletActionContext.getRequest();                
        HttpSession session=request.getSession();                        
        
        if(session.getAttribute("LoginName")==null)
        {   
            String url="";
            url+=actionInvocation.getProxy().getNamespace();
            if(!actionInvocation.getProxy().getActionName().equals(""))
                url+="/"+actionInvocation.getProxy().getActionName();            

            session.setAttribute("url", url);
            return "RedirectToLoginPage";
        }
        else
            return actionInvocation.invoke();
        
    }
    
}
